namespace Brjnk.GpxExplorer.ViewModel
{
    using Brjnk.Common;
    using Brjnk.GpxExplorer.Data;
    using Brjnk.GpxExplorer.Workspace.Searching;
    using Brjnk.MVVM;

    /// <summary>
    /// </summary>
    public class WaypointVM : Wrapper<Waypoint>, IPoint, INamed, IMoveablePoint, IGpsData, ISearchResults, ISelectable, IHideable
    {
        public WaypointVM(Waypoint source)
            : base(source)
        {
        }

        public ObservableCollectionEx<SearchResult> SearchResults { get; set; }

        public GpsCoordinates PositionI
        {
            get { return Source.Position; }
        }

        public string NameI
        {
            get { return Source.Name; }
        }

        private bool isSelected;

        public bool IsSelected
        {
            get { return isSelected; }
            set { isSelected = value; OnPropertyChanged("IsSelected"); }
        }

        private bool isVisible = true;

        public bool IsVisible
        {
            get { return isVisible; }
            set { isVisible = value; OnPropertyChanged("IsVisible"); }
        }

        public void GetBounds(BoundsBuilder builder)
        {
            builder.AddPoint(PositionI);
        }

        protected override void OnSourceObjectPropertyChanged(string propertyName)
        {
            if (propertyName == "Position")
                OnPropertyChanged("PositionI");
            else if (propertyName == "Name")
                OnPropertyChanged("NameI");
        }

        public void Move(GpsCoordinates position)
        {
            Source.Position = position;
        }
    }
}